local M = {}
function M.createKernel()
	local kernel = {
		category = "filter",
		name = "sea",
		isTimeDependent = true,
		vertexData = {
			{
				name = "xSpeed",
				default = 0.008, 
				min = -1,
				max = 1,
				index = 0,  -- This corresponds to "CoronaVertexUserData.x"
			},
			{
				name = "ySpeed",
				default = 0.008, 
				min = -1,
				max = 1,
				index = 1,  -- This corresponds to "CoronaVertexUserData.y"
			},
		},
		fragment = 
		[[
		P_COLOR vec4 drawTex(P_UV vec2 uv)
		{
			// uv.x*3.14*20.0 基础振幅周期 360/(3.14*20.0)为一个基础周期
			//CoronaTotalTime*3.14*0. 5函数偏移量
			//CoronaVertexUserData.x 偏移的缩放比
			uv.x+= sin(uv.x*3.14*20.0 + CoronaTotalTime*3.14*0.5)*CoronaVertexUserData.x;
			uv.y+= sin(uv.y*3.14*20.0 + CoronaTotalTime*3.14*0.5)*CoronaVertexUserData.y;
			P_UV vec2 new_uv = uv;
			P_COLOR vec4 texColor = texture2D( CoronaSampler0, new_uv);
			
			return texColor;
		}

		P_COLOR vec4 FragmentKernel( P_UV vec2 texCoord )
		{
			P_UV vec2 uv = texCoord.xy; //- vec2(0.5,0.5) ;
			return CoronaColorScale(drawTex(uv));
		}
		]],
	}

	return kernel
end


function M.init()
	local kernel = M.createKernel()
	graphics.defineEffect(kernel)
end

M.init()


function M.test()
	local ground = display.newImage("assets/unpack/bg/bg_main.png")
	layout.setXY(ground, SCREEN_CX,0)
	ground.fill.effect = "filter.custom.sea"
	ground.fill.effect.speed = 0.03
end

return M